/*
 * Copyright (c) 2007 IJO Technologies Ltd.
 * www.ijotechnologies.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * IJO Technologies ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you
 * entered into with IJO Technologies.
 */

package com.nervenets.general.hibernate;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.nervenets.general.utils.JodaUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Index;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;

@EqualsAndHashCode(callSuper = true)
@MappedSuperclass
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder
public abstract class DomainObject extends BaseEntity {
    @Index(name = "idx_del_time")
    @Column(name = "del")
    @ApiModelProperty(value = "删除时间戳")
    @JsonIgnore
    private long deleted = 0;
    @Index(name = "idx_create_time")
    @Column(name = "ct")
    @ApiModelProperty(value = "创建时间")
    @Builder.Default
    private long createTime = JodaUtils.getTimestamp();
    @ApiModelProperty(value = "创建人")
    @Index(name = "idx_create_by")
    private long createBy;

    @JsonIgnore
    @JSONField(serialize = false)
    public boolean isDeleted() {
        return this.deleted > 0;
    }
}
